package au.com.ecaporali.module1.introexercises.primefactors;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Enrico on 7/09/2014.
 */
public class PrimeFactors {

    List<Integer> primeFactors = new ArrayList<Integer>();

    public void generate(int n){
        boolean notPrimeFactor = true;

        int i = 2;
        while(i < n && notPrimeFactor){
            if(n % i == 0) primeFactors.add(i);
            if(shouldStop(n)) notPrimeFactor = false;
            i++;
        }
        if(notPrimeFactor) primeFactors.clear();

        show(primeFactors);
    }

    private boolean shouldStop(int n){
        int factor = 1;
        for(Integer num : primeFactors){
            factor *= num;
        }
        return factor == n;
    }

    private void show(List<Integer> primeFactors){
        System.out.println(primeFactors);
    }
}
